package gugu.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "QUESTION")
public class Question extends PositionElement{
	@Id
	private String id;
	private int index;
	private PositionElement errorMsg;
	private PositionElement title;
	private Comment comments;
	private Boolean required;
	private QuestionMeta meta;
	/*private QuestionTypeEnum questionType;
	private DisplayFormatTypeEnum questionDisplayType;
	private String[] answersText;*/
	@DBRef
	private Survey survey;

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
	
	public PositionElement getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(PositionElement errorMsg) {
		this.errorMsg = errorMsg;
	}

	public PositionElement getTitle() {
		return title;
	}

	public void setTitle(PositionElement title) {
		this.title = title;
	}

	public Comment getComments() {
		return comments;
	}

	public void setComments(Comment comments) {
		this.comments = comments;
	}

	public Boolean getRequired() {
		return required;
	}

	public void setRequired(Boolean required) {
		this.required = required;
	}

	public QuestionMeta getMeta() {
		return meta;
	}

	public void setMeta(QuestionMeta meta) {
		this.meta = meta;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Survey getSurvey() {
		return survey;
	}

	public void setSurvey(Survey survey) {
		this.survey = survey;
	}

	/*@Override
	public boolean equals(Object obj) {
		Question q=(Question)obj;
		if(		(q.id.equals(this.id))&&
				(q.index==this.index)&&
				(q.questionText.equals(this.questionText))&&
				(q.questionType.equals(this.questionType))&&
				(q.questionDisplayType.equals(this.questionDisplayType))&&
				(q.isHasOthers().equals(this.isHasOthers()))&&
				(q.toAnswerTextStr().equals(this.toAnswerTextStr()))
		 ) {return true;}
		return false;
	}*/
	
	private String  toAnswerTextStr(){
		StringBuffer sbf=new StringBuffer();
		for(String s:this.answersText){
			sbf.append(s).append(",");
		}
		sbf.deleteCharAt(sbf.length()-1);
		return sbf.toString();
	}

}
